// Copyright (C) 2024 Kumo inc.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//

#pragma once

#include <chrono>
#include <cstddef>
#include <functional>
#include <list>
#include <tuple>
#include <unordered_map>

namespace deneb::internal {

    /// The default capacity for all caches.
    const std::size_t DEFAULT_CAPACITY = 128;

    /// The reference type use to store keys in the order queue.
    template<typename T>
    using Reference = std::reference_wrapper<T>;

    /// Compares two References for equality.
    ///
    /// This is necessary because `std::reference_wrapper` does not define any
    /// operator overloads. We do need them, however (e.g. for container
    /// comparison).
    ///
    /// \param first The first reference to compare.
    /// \param second The second reference to compare.
    template<typename T, typename U>
    bool operator==(const Reference<T> &first, const Reference<U> &second) {
        return first.get() == second.get();
    }

    /// Compares two References for inequality.
    ///
    /// This is necessary because `std::reference_wrapper` does not define any
    /// operator overloads. We do need them, however (e.g. for container
    /// comparison).
    ///
    /// \param first The first reference to compare.
    /// \param second The second reference to compare.
    template<typename T, typename U>
    bool operator!=(const Reference<T> &first, const Reference<U> &second) {
        return !(first == second);
    }

    /// The default queue type used internally.
    template<typename T>
    using Queue = std::list<Reference<T>>;

    /// The default map type used internally.
    template<typename Key,
            typename Information,
            typename HashFunction,
            typename KeyEqual>
    using Map = std::unordered_map<Key, Information, HashFunction, KeyEqual>;

    /// The default clock used internally.
    using Clock = std::chrono::steady_clock;

    /// The default timestamp (time point) used internally.
    using Timestamp = Clock::time_point;
}  // namespace deneb::internal
